﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
    class DBHelper
    {

        public static string Str = "server=.;database=admin;Integrated Security=true";


        //查询
        public static SqlDataReader Select(string sql)
        {
            //创建数据库连接
            SqlConnection conn = new SqlConnection(Str);
            //打开连接
            conn.Open();
            //创建命令对象
            SqlCommand cmd = new SqlCommand(sql, conn);

            //执行ExecuteNonQuery命令
            return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        }


        //增删改
        public static bool Ha(string sql) 
        {
            bool result = false;
            //创建数据库连接
            SqlConnection conn = new SqlConnection(Str);
            //打开连接
            conn.Open();
            //创建命令对象
            SqlCommand cmd = new SqlCommand(sql,conn);

            //执行ExecuteNonQuery命令
            int number = cmd.ExecuteNonQuery();
            if (number == 0)
            {
                result = true;

            }
            //关闭连接
            conn.Close();
            return result;

        }


    }
}
